import React from 'react'

import {Item} from './router-config'

import {Switch,Redirect,Route} from 'react-router-dom'

interface Routes{
    routes:Item[]
}

function RouterView({routes}:Routes){
    //Route Redirect
    let routeArr = routes.filter((item:Item) => item.component);
    let redirectArr = routes.filter((item:Item) => item.redirect);
    return <Switch>
        {routeArr.map((item:Item) => <Route path={item.path} key={item.path} render={(props) => {
            return <item.component routes={item.children} {...props}></item.component>
        }}></Route>)}
        {redirectArr.map((item:Item) => <Redirect  key={item.path} from={item.path} to={item.redirect as string}></Redirect>)}
        
    </Switch>
}

export default RouterView